package com.Arrays;

import java.util.Scanner;

/**
 * @Auther: MFM
 * @Date: 2021/7/13 - 07 - 13 - 19:12
 * @version: 1.0
 */

public class Arrays {
    //静态数组
    private int data[];

    //数组的实际个数
    private int size;

    //空构造器默认为10
    public Arrays() {
        this(10);
    }

    //设置数组长度
    public Arrays(int capacity) {
        data = new int[capacity];
        size = 0;
    }

    //获得实际长度个数
    public int getSize() {
        return size;
    }

    //获得数组容量
    public int getCapacity() {
        return data.length;
    }

    //是否为空
    public boolean isEmpty() {
        return size == 0;
    }

    //在数组末尾添加元素
    public void addLast(int e) {
        if (size == data.length) {
            throw new IllegalArgumentException("添加失败，数组已满");
        }

        data[size] = e;
        size++;
    }

    //在数组中间添加元素
    public void add(int e, int index) {
        if (index < 0 || index > size) {
            throw new IllegalArgumentException("添加失败，参数不合法");
        }
        for (int i = size - 1; i >= index; i--) {
            data[i + 1] = data[i];
        }
        data[index] = e;
        size++;
    }

    public void addFirst(int e) {
        add(e, e);
    }

    @Override
    public String toString() {
        StringBuilder res = new StringBuilder();
        res.append("[");
        

        return res.toString();
    }
}
